<?php

namespace App\Model;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Model\UserMsg
 *
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg query()
 * @mixin \Eloquent
 * @property int $id
 * @property string $title 标题
 * @property string $content 内容
 * @property int $type 1送脉宝 2分享 3企业邀请
 * @property int $from_user_id
 * @property int $to_user_id
 * @property \Illuminate\Support\Carbon $created_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereFromUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereToUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserMsg whereType($value)
 */
class UserMsg extends Model
{
	const MAIBAO = 1; //送脉宝
	const SHARE = 2;    //分享
	const ENTERPRISE = 3;//企业邀请
	protected $table = 'user_msg';

	/**
	 * @param $title 标题
	 * @param $content 内容
	 * @param $type 类型
	 * @param $from_user_id 发送者
	 * @param $to_user_id 接受者
	 * @return bool
	 */
	public static function add($title, $content, $type, $from_user_id, $to_user_id): bool
	{
		return self::insert([
			'title' => $title,
			'content' => $content,
			'type' => $type,
			'from_user_id' => $from_user_id,
			'to_user_id' => $to_user_id,
			'created_at' => Carbon::now(),
		]);
	}
}
